import React, { Component, createContext } from "react";
import Child1 from "./Child1";

export const context = createContext();

class App extends Component {
  state = {
    count: 10,
  };

  add = () => {
    this.setState((prevState) => {
      return {
        count: prevState.count + 1,
      };
    });
  };

  minus = () => {
    this.setState((prevState) => {
      return {
        count: prevState.count - 1,
      };
    });
  };

  render() {
    return (
      <context.Provider
        value={{
          count: this.state.count,
          add: this.add,
          minus: this.minus,
        }}
      >
        <h2>context计数器</h2>
        <Child1 />
      </context.Provider>
    );
  }
}

export default App;
